<template lang="pug">
div
  h2.side__menu__title 课本
    .side__menu__control
      .side__menu__switch(@click.prevent="addNode")
        i.icon_switch_normal
        | 添加
      .side__menu__switch(@click.prevent="selectBook")
        i.icon_switch_normal
        | 切换
      .side__menu__switch(@click.prevent="modifyNode")
        i.icon_switch_normal
        | 修改
      .side__menu__switch(@click.prevent="")
        i.icon_switch_normal
        | 删除
  h3.side__menu__dt 高二课本
  ul.side__menu__list
    li(v-for="item in books", v-if="item.level === 1")
      router-link.side__menu__sub.expand(:to="'/teacher/lession/' + item.catalogId") {{item.catalogName}}
      ul(v-for="level2 in books", v-if="level2.level === 2")
        li
          router-link.side__menu__sub(:to="'/teacher/lession/' + level2.catalogId") {{level2.catalogName}}
          ul(v-for="level3 in books", v-if="level3.level === 3 && level3.parentId === level2.catalogId")
            li
              router-link(:to="'/teacher/lession/' + level3.catalogId") {{level3.catalogName}}
</template>
<script>
import student from 'api/lession'
export default {
  data () {
    return {
      books: []
    }
  },
  mounted () {
    this.getBooks()
  },
  computed: {
    currentBook () {
      return this.books.find(item => {
        return item.catalogId === (this.$route.params.catelogid || '1')
      })
    }
  },
  methods: {
    getBooks () {
      student.getBooks('119907809079853056').then(response => {
        this.books = response.data.data
      })
    },
    selectBook () {
      this.$store.commit('show', 'switchLession')
    },
    addNode () {
      this.$store.commit('changeNode', {
        type: 'add',
        data: this.currentBook
      })
      this.$store.commit('show', 'addNode')
    },
    modifyNode () {
      this.$store.commit('changeNode', {
        type: 'modify',
        data: this.currentBook
      })
      this.$store.commit('show', 'addNode')
    }
  }
}
</script>
